package queue_stack;

import java.util.ArrayDeque;
import java.util.Queue;


/**
 * 队列实现栈
 *
 * push 后记得交换一下
 */
class QueueToStack {

    Queue<Integer> q1=new ArrayDeque<>();
    Queue<Integer> q2=new ArrayDeque<>();

    public QueueToStack() {
        
    }
    
    public void push(int x) {
        q2.offer(x);

        while(!q1.isEmpty()){
            q2.offer(q1.poll());
        }

        //交换一下
        Queue<Integer> tmp=q2;
        q2=q1;
        q1=tmp;
    }
    
    public int pop() {
        return q1.poll();
    }
    
    public int top() {
        return q1.peek();
    }
    
    public boolean empty() {
        return q1.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */